const {
	$U_UserInfo,
	$U_SetItem,
	$U_GetItem,
	$U_RemoveItem,
} = require('@utils/storage')

const I64BIT_TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'.split('');

module.exports = {
	/**
	 * 设置接口详情控件是否可编辑
	 * @param {[type]} apiComp [description]
	 */
	setFormEdit,

	/**
	 * 设置编辑按钮显示情况
	 * @param {[type]} apiComp [description]
	 */
	setBtnEdit,

	setEditStatus(apiComp) {
		setFormEdit(apiComp)
		setBtnEdit(apiComp)
	},

	/**
	 * 随机数ID
	 * @return {[type]} [description]
	 */
	randomId() {
		// return `${Math.random()}`.replace(/^0\./, '')
		return $.md5(`${Math.random()}`)
	},

	dialogClose() {
		this.store.isSave = true
	},

	clearTmpProjectData() {
		$U_RemoveItem('tmp_edit_project_data')
		$U_RemoveItem('tmp_history')
		$U_RemoveItem('tmp_current_check_api')
	},
}

/**
 * 设置接口详情控件是否可编辑
 * @param {[type]} apiComp [description]
 */
function setFormEdit(apiComp) {
	let {
		store,
		formComp,
		formPath,
		formContentType,
		formMethod,
		formIntro,
	} = apiComp
	let opts = store.isLock ? 'enable' : 'disable'
	formPath.textbox(opts)
	formIntro.textbox(opts)
	formContentType.combobox(opts)
	formMethod.combobox(opts)
}

/**
 * 设置编辑按钮显示情况
 * @param {[type]} apiComp [description]
 */
function setBtnEdit(apiComp) {
	let {
		store,
		btnCancel,
		btnSave,
		btnQuickSave,
		btnEdit,
		btnVersion,
	} = apiComp
	let opts = store.isLock ? 'enable' : 'disable'
	let unopts = store.isLock ? 'disable' : 'enable'
	btnCancel.linkbutton(opts)
	btnSave.linkbutton(opts)
	btnQuickSave.linkbutton(opts)
	btnEdit.linkbutton(unopts)
	btnVersion.linkbutton(unopts)
}